﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Collections.ObjectModel;
using System.Collections;

namespace CitrixPVSWrapper
{

    [System.Management.Automation.Cmdlet("RunWithReturn", "PvsServerName", SupportsShouldProcess = true)]
    public class Run_PvsServerName : System.Management.Automation.PSCmdlet
    {

        protected override void ProcessRecord()
        {
            // Verbose and Debug Settings
            Boolean Verbose = this.MyInvocation.BoundParameters.ContainsKey("Verbose");
            WriteVerbose("Verbose Flag: " + Verbose);
            Boolean Debug = this.MyInvocation.BoundParameters.ContainsKey("Debug");
            WriteDebug("Debug Flag: " + Debug);

            // Collections to hold the queries and the results
            string TargetObject = "ServerName";

            //Build the query object
            QueryDefinition RunQuery = new QueryDefinition(QueryActionType.RunWithReturn, TargetObject);

            string ShouldProcessMessage = "Get the name of the currently connected SOAP server";
           
            // Perform the actual Run and return any errors
            if (ShouldProcess(ShouldProcessMessage))
            {
                foreach (string[] Record in PvsHelpers.ExecuteMcliQuery(RunQuery, Verbose, Debug))
                {
                    WriteDebug("Returning Object");
                    WriteObject(PvsHelpers.Get_StringValueFromRecord("ServerName", Record, Verbose));
                }
            }
        }
    }
}
